In a prior art, an entity that has the audio playing function such as a multimedia mobile phone and a Moving Picture Experts Group Audio Layer III (MP3) player may play audio files stored in the entity or player or locate and search for any position in these audio files. The file structure of audio files, such as the audio files of the MP3 or Advanced Audio Coding (AAC) type, consists of multi-frame data. Each frame includes frame header data and audio data. The frame header data records the audio information of the data frame, such as the sampling rate, channel mode, and frame length. The audio data is the data that is processed through a specific compression algorithm.
Playing an audio file includes two processes, namely, parsing and decoding. Parsing is a process of obtaining audio information from the frame header of a frame contained in an audio file. Decoding is a process of restoring audio data that is processed through a compression algorithm to original Pulse Code Modulation (PCM) data.
As shown in FIG. 1, when an audio file is played in a prior art, the type of the file is determined preliminarily according to the suffix of the file, and each frame of the file is parsed according to the type to obtain audio information of each frame, such as the sampling rate, channel mode, and frame length. The file information such as the sampling rate, total playing duration, and total number of frames is obtained by parsing the whole file. After the whole file is parsed, the first data frame starts to be decoded and played.
Two processes, namely, locating and playing, are included in the location and search of an audio file. Locating is a process of determining the position of a frame that is played first according to the search time in an input search command. Playing is a process of decoding and playing audio data from the determined start frame position.
As shown in FIG. 2, before the location and search of an audio file, validity of the search time in the search command needs to be checked. If the search time is valid, location and search can be performed. During location and search, a locating operation is performed according to the search time. The specific method is as follows: the playing duration is cumulated from the first frame of the audio file; the playing duration of each frame can be obtained from the frame header data of the data frame; when the cumulative playing duration until a frame is longer than or equal to the search time, the frame is taken as the start frame to be played. From the start frame, audio data is decoded and played. For example, if the search time is 5 s, and the playing duration of each frame is 10 ms, the cumulative playing duration until the 500th frame is 5 s (500×10 ms). Then the 500th frame is taken as the start frame to be played, and data is read from the 500th frame for decoding and playing.
In the process of implementing the present invention, the inventor finds at least the following technical defects in the prior art:
After a user starts playing an audio file, the user can hear the audio only after waiting for a long period of time due to the lower response speed. This is because the file can be played only after all the frames of the file are read and parsed when the audio file is played. When the size of a file is large, the reading speed is very low. For example, an MP3 file with the size of four MB is stored in an external storage such as a Secure Digital (SD) card; if the reading speed is one MB per second, about four seconds are required to read the entire file; that is, the user can hear the music after at least four seconds when starting playing the audio file.
Every time the user starts location and search, data starts to be read from the first frame of an audio File in the locating process, and the playing duration is cumulated until the frame position where the cumulative duration meets the search time is found. The method for location and search from the start of the file frame by frame is inefficient, and the playing response speed is low. When the search time point is close to the end time, the locating process needs to traverse the entire file. In the case of a large-sized file stored on a low-speed device, the locating process takes a longer time.